var table;
var calssify = GetQueryString("calssify");
function GetQueryString(name) {
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null)
        return  unescape(r[2]);
    return null;
}
layui.use('table', function(){
    var calssifyInt=parseInt(calssify);
    table = layui.table
        ,form = layui.form;
    table.render({
        elem: '#test'
        ,url:'/Finace/JsonFinaceList?calssify='+calssifyInt
        ,cellMinWidth: 100
        ,cols: [[
            {type:'numbers'}
            ,{type: 'checkbox'}
            // ,{field:'financeId', title:'ID'}
            ,{field:'userId', title:'用户ID' }
            ,{field:'userNo', title:'用户编号' }
             ,{field:'amount', title:'金额'}
            ,{field:'balance', title: '余额'}
            ,{field:'finaceTime',title: '时间',templet :function (row){return createTime(row.finaceTime);}}
            ,{field:'remark', title: '备注'}
            // ,{field:'opratorUId', title: 'UID'}
            // ,{field:'opratorId', title: 'AID'}
        ]]
        ,page: true
        ,limit:10
        ,id: 'testReload'
    });

    //监听表格复选框选择
    table.on('checkbox(demo)', function(obj){
        console.log(obj)
    });
});

function createTime(v){
    return new Date(parseInt(v)).toLocaleString()
}
/**重写toLocaleString方法*/
Date.prototype.toLocaleString = function() {
    var y = this.getFullYear();
    var m = this.getMonth()+1;
    m = m<10?'0'+m:m;
    var d = this.getDate();
    d = d<10?("0"+d):d;
    var h = this.getHours();
    h = h<10?("0"+h):h;
    var M = this.getMinutes();
    M = M<10?("0"+M):M;
    var S=this.getSeconds();
    S=S<10?("0"+S):S;
    return y+"-"+m+"-"+d+" "+h+":"+M+":"+S;}


function WinOpenAdd() {
    layer.open({
        type: 2
        , title: '会员编号充值'
        , content: '/Finace/getFinaceAdd'
        , area: ['420px', '420px']
        , btn: ['确定', '取消']
        , yes: function (index, layero) {
            var body = layer.getChildFrame('body', index); //得到iframe页的body内容
            var userId = body.find("#userId").val();
            var amount = body.find("#amount").val();

            if(userId!=null&&userId!="") {
                var amount = body.find("#amount").val();
                var remark = body.find("#remark").val();
                var addUrl = '/Finace/FinaceAdd?calssify='+ calssify + '&userId=' + userId + '&amount=' + amount+"&remark="+remark;
                $.ajax({
                    url: addUrl,
                    type: "GET",
                    dataType: "json", //指定服务器返回的数据类型
                    async: false,
                    success: function (result) {
                            layer.alert(result.result);
                    }
                });
                //数据刷新
                var demoReload = $('#demoReload');
                //执行重载
                table.reload('testReload', {});
                layer.close(index); //关闭弹层
            }
            else
            {
                layer.alert("用户不存在");
            }
        }
    });
}

function SelectData() {
    //数据刷新
    var userNo = $('#userNo').val();
    //执行重载
    table.reload('testReload', {
        url:'/Finace/JsonFinaceList?calssify='+calssify+'&userNo='+userNo,
        page: {
            curr: 1 //重新从第 1 页开始
        }
    });



}